﻿

namespace Tentacle.Scheduler
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Net;
    using System.Text;
    //
    using Tentacle.Core;
    using Tentacle.Downloader;
    using Tentacle.Pipeline;
    using Tentacle.Processor;

    public interface IScheduler
    {
        /// <summary>
        /// 获取或设置当前调度器的调度周期(单位为ms,默认值为0)
        /// </summary>
        /// <remarks>调度周期决定Worker的延迟时间，在这个时间之内调度器不会调度该Worker</remarks>
        int PeroidTime { get; set; }

        /// <summary>
        /// 获取或设置当前Worker集合
        /// </summary>
        IEnumerable<IDownloader> Downloader { get; set; }

        /// <summary>
        /// 获取当前调度器持有的任务队列
        /// </summary>
        Queue<WebSite> TaskQueue { get; }

        /// <summary>
        /// 获取当前调度器持有的最近任务队列
        /// </summary>
        Queue<WebSite> RecentTask { get; }

        /// <summary>
        /// 获取当前调度器持有的完成池
        /// </summary>
        /// <remarks>该对象能够实现Url去重</remarks>
        IEnumerable<WebSite> FinishedPool { get; }

        /// <summary>
        /// 
        /// </summary>
        int FinishedCount { get; }

        /// <summary>
        /// 获取页面处理器集合
        /// </summary>
        IEnumerable<IPageProcessor> Processors { get;}

        /// <summary>
        /// 
        /// </summary>
        WebToken Token { get; set; }

        /// <summary>
        /// 
        /// </summary>
        WebProxy Proxy { get; set; }

        /// <summary>
        /// 设置指定的入口页面，开始采集网站
        /// </summary>
        /// <param name="startPage">该网站的入口地址</param>
        void Start(WebSite startPage);

        /// <summary>
        /// 设置单个页面处理器
        /// </summary>
        /// <param name="processor">指定全局页面处理器</param>
        void SetPageProcessor(IPageProcessor processor);

        /// <summary>
        /// 设置多个页面处理器
        /// </summary>
        /// <param name="processors">指定的页面处理器集合(如果调用了该设置，则会取消上一次设置的页面处理器)</param>
        /// <remarks>调用该方法之前请确保用户自定义的PageProcessor实现了IsPageMatch方法</remarks>
        void SetPageProcessor(IPageProcessor[] processors);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pipeline"></param>
        void SetPipeline(IWebPipeline pipeline);

        /// <summary>
        /// 事务回滚
        /// </summary>
        /// <param name="site"></param>
        void Rollback(WebSite site);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sites"></param>
        /// <param name="nametable"></param>
        void RebuildProgress(string[] sites, string[] nametable);

        /// <summary>
        /// 
        /// </summary>
        DownloadFailedHandler DownloadFailed { get; set; }

        /// <summary>
        /// 
        /// </summary>
        DownloadCompletedHandler DownloadCompleted { get; set; }
    }
}
